import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:zpp_sdzx/pages/cleanobjects/cleanlogin%20copy.dart';
import 'package:zpp_sdzx/pages/cleanobjects/cleanlogin2.dart';
import 'package:zpp_sdzx/pages/cleanobjects/cleanobjects_list.dart';
import 'package:zpp_sdzx/pages/cleanobjects/cleanobjects_list2.dart';
import '../../pages/docsend/docsend_add.dart';
import '../../pages/docsend/docsend_list.dart';
import '../../pages/jxgzp/jxgzp_home.dart';
import '../../pages/security/security_list.dart';
import '../../spaces/filespace/fileSpace_list.dart';
import '../../pages/sdzx/sdzx_home.dart';
import '../../helper/channelHelper.dart';
import '../smspage/sms_page.dart';

class MyHomePage extends StatefulWidget {
  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  bool isQuit = false;
// 清除标记定时器
  late Timer quitTimer;

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
      // 捕获用户操作，判断能否返回
      onWillPop: () async {
        // 可以返回
        if (!Navigator.canPop(context)) {
          // 检查退出标记
          if (isQuit) {
            // 退出APP
            await SystemChannels.platform.invokeMethod('SystemNavigator.pop');
          } else {
            // 我包装的提示工具类，提示用户再次点击退出，使用的fluttertoast插件
            ChannelHelper.showToast("再次点击退出！");
            // 记录退出标记
            isQuit = true;
            // 开启定时器，两秒后清除标记
            quitTimer = Timer(Duration(seconds: 2), () {
              isQuit = false;
              quitTimer.cancel();
            });
          }
          // 阻止返回
          return false;
        }
        // 默认正常运行
        return true;
      },
      //   child : JXGZPPage(),

      child: SmsSendPage(true),
      // child : DocSendListPage(true),
    );
  }
}
